package com.zangchat.controller;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import com.zangchat.domain.ChatLogTalk;
import com.zangchat.service.IChatLogTalkService;

/**
 * 聊天记录Controller
 * 
 * @author ruoyi
 * @date 2020-07-29
 */
@RestController
@RequestMapping("/zangchat/talklog")
public class ChatLogTalkController extends BaseController
{

    @Autowired
    private IChatLogTalkService chatLogTalkService;

    /**
     * 聊天/语音记录
     * @param fromId 发起人id
     * @param receiveId 接收人id
     * @param startTime 开始时间
     * @param overTime 结束时间
     * @param talkTime 时长
     * @param type 类型 1 聊天  2 视频
     * @param isFree 是否免费聊天
     * @return
     */
    @RequestMapping("/saveLogTalk")
    public AjaxResult saveLogTalk(@ModelAttribute("fromId") Long fromId,
                                  @ModelAttribute("receiveId") Long receiveId,
                                  @ModelAttribute("startTime") Date startTime,
                                  @ModelAttribute("overTime") Date overTime,
                                  @ModelAttribute("talkTime") Long talkTime,
                                  @ModelAttribute("type") int type,
                                  @ModelAttribute("isFree") Boolean isFree){
        return toAjax(chatLogTalkService.saveLogTalk(fromId,receiveId,startTime,overTime,talkTime,type,isFree)) ;

    }

    /**
     * 校验聊天
     * @param fromId 发起人
     * @param receiveId 接收人
     * @param startTime 开始时间
     * @param type 类型 1 聊天  2 视频
     * @return
     */
    @RequestMapping("/checkedLogTalk")
    public AjaxResult checkedLogTalk(@ModelAttribute("fromId") Long fromId,
                                  @ModelAttribute("receiveId") Long receiveId,
                                  @ModelAttribute("startTime") Date startTime,
                                  @ModelAttribute("type") int type){
        return chatLogTalkService.checkedTalk(fromId,receiveId,startTime,type) ;
    }

    /**
     * 查看聊天记录
     * @param userId 用户id
     * @param pageNum 页数
     * @param pageSize 每页条数
     * @return
     */
    @RequestMapping("/selectLogTalk")
    public AjaxResult selectLogTalk(@ModelAttribute("userId")Long userId,
                                    @ModelAttribute("pageNum")int pageNum,
                                    @ModelAttribute("pageSize")int pageSize){

       return chatLogTalkService.selectLogTalk(userId,pageNum,pageSize);
    }
}
